<!--
* @description  : 抽样物品选择
* @descriptionDetail: 抽样物品选择
* @copyright    : 浙江烟草
* @author       : sy
* @create       : 2022-07-25 16:15:38
-->
<template>
  <view class="single-page">
    <theme-navbar
      :isBack="false"
      :is-white="false"
      title="抽样物品选择"
    >
      <view class="nav-right-icon">
        <u-icon color="#FFF" name="more-dot-fill" size="38" @click="isOpen = true"></u-icon>
        <text class="u-p-l-25" @click="confirmBack">
          确定
        </text>
      </view>
    </theme-navbar>
    <!-- 关联文书操作 -->
    <u-popup mode="top" border-radius="14" v-model="isOpen">
      <u-row>
        <u-col span="12" class="right-menu-item" v-for="(docIns, idx) in regsList" :key="idx" @tap="handlerDeal(docIns)">
          <span class="text">{{ docIns.fullDocNo }}</span>
        </u-col>
      </u-row>
    </u-popup>
    <view class="content">
      <u-row class="credit-container desc-title">
        <u-col span="6" style="padding-right:0;">
          品种规格
        </u-col>
        <u-col span="3">
          样品基数(条)
        </u-col>
        <u-col span="3">
          抽样数量(条)
        </u-col>
      </u-row>
      <u-row
        class="credit-container"
        v-for="(item, idx) in mDatas"
        :key="idx"
      >
        <u-col span="6" style="padding-right:0;">
          <view class="title">
            {{ item.goodsName || '&nbsp;' }}
          </view>
        </u-col>
        <u-col span="3">
          {{ item.qty || '&nbsp;' }}
        </u-col>
        <u-col span="3">
          {{ item.handleQty || '&nbsp;' }}
        </u-col>
      </u-row>
      <view class="no-more-results" v-if="mDatas.length==0">
        ~没有更多数据了~
      </view>
    </view>
  </view>
</template>

<script>
import officeService from "@/service/case/office.service.js";
export default {
  name: "SingleSelect",
  props: {
    caseUuid:{
      type:String,
      default:"",
    },
  },
  data() {
    return {
      borderNone:{ 'border-top': 'none','border-left':'none', },
      isOpen:false,
      selectedItem: {},     // 选中项
      mDatas:[],
      allType:[{
        fullDocNo:'全部',
        goodsRegUuid:'',
      },],
      regsList:[],
      goodsRegUuid:'',
    };
  },
  created(){
    this.initDocInfo();
    this.initGoodsInfo();
  },
  methods: {
    // 先保书下拉框数据初始化
    initDocInfo(){
      officeService.getDoodsRegs({caseUuid:this.caseUuid,}).then(regs => {
        if(regs.success){
          this.regsList = [...this.allType,...regs.data,];
        }else{
          this.$u.toast(regs.msg);
        }
      });
    },
    // 抽样物品数据初始化
    initGoodsInfo(){
      this.$u.loading('数据加载中...');
      let parms = {
        caseUuid: this.caseUuid,
        goodsRegUuid: this.goodsRegUuid,
        page:1,
        limit:1000,
      }
      officeService.chooseGoods(parms).then(dr => {
        this.$u.hideLoading();
        if (dr.success) {
          let ps = dr.data;
          this.$nextTick(() => {
            this.mDatas = ps;
          });
        }
      }).catch(err => {
        this.$u.hideLoading();
        this.$u.toast(err);
      });
    },
    confirmBack(){
      this.mDatas.forEach(ps => {
        this.$set(ps,'baseQty',ps.qty ? ps.qty : '');
        this.$set(ps,'sampleQty',ps.handleQty ? ps.handleQty : '');
      });
      this.$emit("m-select", this.mDatas);
    },
    // 先保书选择
    handlerDeal(doc){
      this.goodsRegUuid = doc.goodsRegUuid;
      this.isOpen = false;
      this.initGoodsInfo();
    },
  },
};
</script>
<style lang="scss" scoped>
.single-page {
  padding: 10px;
  .nav-right-icon {
    color: #FFF;
    margin-right: 15px;
  }
  .u-checkbox-group {
    width: 100%;
  }
  .credit-container {
    height: 88rpx;
    border-bottom: 1px solid #e6e6e6;
  }
  .title {
    text-overflow: ellipsis;
    word-break: break-all;
    overflow: hidden;
    white-space: nowrap;
  }
}
.no-more-results {
  color: #999;
  text-align: center;
  margin-top: 15px;
}
.desc-title{
  background: #EFF3F9;
}
.right-menu-item {
  height: 44px;
  line-height: 44px;
  border: 1px solid #f3f3f3;
  .icon {
    color: #666;
  }
  .text {
    margin-left: 15px;
    color: #333;
  }
}
</style>